package com.chen.integral.module.integral.service.impl;

import com.chen.base.module.base.dto.Response;
import com.chen.base.module.base.service.impl.BaseServiceImpl;
import com.chen.dao.integral.IntegralBalanceDao;
import com.chen.entity.integral.IntegralBalance;
import com.chen.integral.module.integral.service.IntegralBalanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @Title: manager-spring-mvc-hb
 * @Description: to do
 * @Author: chenjiwei
 * @Date: 2020-11-16 23:28
 * @Version: 1.0.0
 */
@Service
public class IntegralBalanceServiceImpl extends BaseServiceImpl<IntegralBalance> implements IntegralBalanceService<IntegralBalance> {

    @Autowired
    private IntegralBalanceDao integralBalanceDao;

    @Override
    public JpaSpecificationExecutor getBaseRepository() {
        return integralBalanceDao;
    }

    @Override
    protected String filterForFindAll() {
        return null;
    }

    @Override
    public Response addPoint(BigDecimal balance, String userId) {
        IntegralBalance integralBalance = integralBalanceDao.findByIntegralUserId(userId);
        integralBalance.setBalance(integralBalance.getBalance().add(balance));
        integralBalanceDao.save(integralBalance);
        return Response.success("余额新增成功");
    }

    @Override
    public IntegralBalance queryByUserId(String userId) {
        return integralBalanceDao.findByIntegralUserId(userId);
    }
}
